import Mock from "mockjs"
function getParams(url) {
    let params = {}
    const urlParams = url.split('?')[1]
    const paramArray = urlParams.split('&')
    paramArray.forEach(item => {
        const param = item.split('=')
        const key = param[0]
        const value = param[1]
        params[key] = parseInt(value)
    })
    return params
}
const {array} = Mock.mock({
    'array|200':[
        {
            "name|+1": [
                "张三",
                "李四",
                "王五"
            ],
            "date|+1": [
                "2022/1/1",
                "2022/11/11",
                "2022/12/12"
            ],
            "address|+1": [
                "浙江杭州",
                "上海万达",
                "四川成都"
            ],
        }
    ]
})
export default [
    Mock.mock(
        RegExp('/api/demoList*'), 'get', (options) => {
            const {page,pre_size} = getParams(options.url)
            const list=[]
            for(let i=(page-1)*pre_size;i<(page-1)*pre_size+pre_size;i++){
                list.push(array[i])
            }
            console.log(list)
            return {
                code: 200,
                data: {
                    total:200,
                    list
                },
                msg: ''
            }
        })
]